

<template>
  <choose-warehouse ref="chooseWarehouseCom" @chooseEvent="d=>{
        inStorageObj.product.warehouse=d;
      }"></choose-warehouse>
  <div class="mt-70">
    <div class="m-[10px] w-[100vw] flex flex-col gap-[10px]">
      <van-field class="rounded-[10px] h-[60px] flex items-center" label="良品数量" v-model="inStorageObj.product.goodNum"
                 placeholder="请输入" />
      <van-field class="rounded-[10px] h-[60px] flex items-center" label="入库数量" v-model="inStorageObj.product.putNum"
        placeholder="请输入" />

      <van-field class="rounded-[10px] h-[60px] flex items-center" label="选择库位" v-model="inStorageObj.product.warehouse"
        placeholder="点击选择库位" readonly @click="()=>{
            chooseWarehouseCom.apply();
        }"/>
      <van-field class="rounded-[10px] h-[120px] flex items-center" label="备注" v-model="inStorageObj.product.remark"
                 type="textarea"
        placeholder="备注信息"
      >
      </van-field>
      <StepBottom v-model="inStorageObj">
        <template #default>
          <div>
            <span class="step-bottom-h2" @click="() => {
              onBack()
            }">取消</span>
          </div>
          <el-button class="step-bottom-button flex flex-col justify-center items-center text-white" @click="() => {
            ensure()
          }">确认入库</el-button>
        </template>
      </StepBottom>
    </div>

  </div>
</template>
<script setup>
// import { putStorage, queryPreregisterApp } from '@/api/Base/preregister';
import {putProductStorage, putProductStorageByApp} from '@/api/Base/preregister';
import { showConfirmDialog,showDialog  } from "vant";
import useAppStore from '@/stores/modules/app';
import { to } from '@/utils/routerUtil';
import { format, subMonths } from 'date-fns';
import chooseWarehouse from '@/components/chooseWarehouse.vue';
definePage({
  name: 'inStorage',
  meta: {
    level: 2,
    title: '入库',
  },
})
const load = ref(false)

const inStorageObj = reactive({
  product: {
    putNum: 0,
    goodNum:0,
    warehouse: "",
    remark:""
  },
  reload: () => {
    // queryPreregisterApp({
    //   page: 1,
    //   pageSize: 999999,
    //   startTime: arriveObj.search.startTime,
    //   endTime: arriveObj.search.endTime,
    //   keyword: arriveObj.search.searchText,
    //   status: arriveObj.search.active
    // }).then(res => {
    //   if (res.code == 0) {
    //     arriveObj.list = res.data.list
    //   }
    // })
  }
})

const router = useRouter()

function onBack() {
  if (window.history.state.back)
    history.back()
  else
    router.replace('/')
}

const route = useRoute()
function ensure() {
  putProductStorageByApp({
    "putStorageNumber": inStorageObj.product.putNum,
    "warehouseNumber": inStorageObj.product.warehouse,
    "remark": inStorageObj.product.remark,
    "preregisterNo": route.query.id
  }).then(res => {
    if (res.code == 0) {
      showDialog({
        title: "入库成功",
        message: "已经入库成功"
      }).then(() => {

      }).catch(() => {
        onBack()
      })
    }else{
      showDialog({
        title: "入库失败",
        message: res.message
      }).then(() => {

      }).catch(() => {
        onBack()
      })
    }

  })
}
onMounted(() => {
  console.log(route.query.id);
  console.log(route.query.no);
  inStorageObj.product.putNum = route.query.num
})
let chooseWarehouseCom=ref(null);

</script>
<style lang="less" scoped>
.search {
  // width: 110px;
  height: 2rem;
  border-radius: 5px;
  opacity: 1;

  /* 纯白 */
  background: #FFFFFF;

}
</style>
